﻿using System;
using System.IO;
using System.Security;

namespace Program12
{
    class Program
    {
        //Directory 文件夹的处理
        static void Main(string[] args)
        {
            //创建文件夹
            Directory.CreateDirectory(@"d:\abc");
            Console.WriteLine("创建成功");

            //try
            //{
            //    Directory.Delete(@"d:\abc");
            //    Console.WriteLine("删除文件夹成功");
            //}
            //catch
            //{
            //    Console.WriteLine("文件夹不存在");
            //}

            //移动文件夹，无法跨盘移动
            //Directory.Move(@"d:\abc", @"d:\bbb\123");
            //Console.WriteLine("剪切成功"); 

            //查询文件夹
            //try
            //{
            //    string[] path = Directory.GetFiles(@"d:\bbb","*.*");
            //    for (var i = 0; i < path.Length; i++)
            //    {
            //        Console.WriteLine(path[i]);
            //    }
            //}
            //catch
            //{
            //    Console.WriteLine("文件夹或文件不存在");
            //}

            //列出文件夹
            string keyPath = "99";
            string[] path = Directory.GetDirectories(@"d:\abc");
            foreach (var p in path)
            {
                if (p.Contains(keyPath))
                    Console.WriteLine(p);
                break;
            }

            //string[] path = Directory.GetDirectories(@"d:\abc");
            //foreach (var p in path)
            //{
            //    Console.WriteLine(p);
            //}

            //列出文件
            //string[] files = Directory.GetFiles(@"d:\bbb", "*.*");
            //foreach(var f in files)
            //{
            //    Console.WriteLine(f);
            //}


            //判断某个文件夹是否存在
            //if (Directory.Exists(@"d:\abc\"))
            //{
            //    for (var i = 0; i < 100; i++)
            //    {
            //        Directory.CreateDirectory(@"d:\abc\" + i);
            //    }
            //}
        }
    }
}
